
import 'package:flutter/material.dart';
import 'package:fzcgx_app/common/adapter_utils.dart';
import 'package:fzcgx_app/provider/provider_widget.dart';
import 'package:fzcgx_app/ui/login/view_model/login_view_model.dart';
import 'package:fzcgx_app/ui/register/page/register_page.dart';
import 'package:nav_router/nav_router.dart';

class LoginPage extends StatefulWidget {
  LoginPage({Key key}) : super(key: key);

  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SafeArea(
      child: ProviderWidget<LoginViewModel>(
        model: LoginViewModel(),
        builder: (context, model, child) {
          return SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(
                  height: AdapterUtils.getHeight(15),
                ),
                Padding(
                  padding: EdgeInsets.only(left: AdapterUtils.getWidth(22)),
                  child: Image.asset(
                    'assets/images/delete.png',
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(54),
                ),
                Container(
                    padding: EdgeInsets.only(left: AdapterUtils.getWidth(48)),
                    child: Text(
                      '欢迎来到',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(15),
                        color: Color(0xff666666),
                        fontWeight: FontWeight.w500,
                      ),
                    )),
                SizedBox(
                  height: AdapterUtils.getHeight(4),
                ),
                Container(
                    padding: EdgeInsets.only(left: AdapterUtils.getWidth(48)),
                    child: Text('美策科技',
                        style: TextStyle(
                          fontSize: AdapterUtils.getSp(28),
                          color: Color(0xff000000),
                          fontWeight: FontWeight.w600,
                        ))),
                SizedBox(
                  height: AdapterUtils.getHeight(57),
                ),
                Container(
                  margin: EdgeInsets.symmetric(
                      horizontal: AdapterUtils.getWidth(50)),
                  padding: EdgeInsets.only(bottom: AdapterUtils.getHeight(10)),
                  decoration: BoxDecoration(
                      border: Border(
                          bottom:
                              BorderSide(color: Color(0xffcccccc), width: 1))),
                  child: Row(
                    children: <Widget>[
                      Text(
                        '+86',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Color(0xff000000),
                            fontSize: AdapterUtils.getSp(16)),
                      ),
                      SizedBox(
                        width: AdapterUtils.getWidth(15),
                      ),
                      Container(
                        height: AdapterUtils.getHeight(19),
                        width: 1,
                        color: Color(0xffcccccc),
                      ),
                      SizedBox(
                        width: AdapterUtils.getWidth(15),
                      ),
                      Expanded(
                        child: TextField(
                          controller: model.phoneControll,
                          keyboardType: TextInputType.phone,
                          onChanged: (value) {
                            model.onChanged();
                          },
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(16),
                            color: Color(0xff000000),
                            fontWeight: FontWeight.w500,
                          ),
                          decoration: InputDecoration(
                              hintText: '输入手机号',
                              border: InputBorder.none,
                              hintStyle: TextStyle(
                                fontSize: AdapterUtils.getSp(16),
                                color: Color(0xffcccccc),
                                fontWeight: FontWeight.w500,
                              )),
                        ),
                      ),
                      Offstage(
                        offstage: model.phoneControll.text.toString().isEmpty
                            ? true
                            : false,
                        child: GestureDetector(
                          onTap: () {
                            model.clearPhoneText();
                          },
                          child: Container(
                            width: AdapterUtils.getWidth(45),
                            height: AdapterUtils.getHeight(45),
                            child: Icon(
                              Icons.cancel,
                              color: Color(0xffc2c2c2),
                              size: 17,
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(20),
                ),
                Container(
                  margin: EdgeInsets.symmetric(
                      horizontal: AdapterUtils.getWidth(50)),
                  padding: EdgeInsets.only(bottom: AdapterUtils.getHeight(10)),
                  decoration: BoxDecoration(
                      border: Border(
                          bottom:
                              BorderSide(color: Color(0xffcccccc), width: 1))),
                  child: Row(
                    children: <Widget>[
                      Expanded(
                        child: TextField(
                          controller: model.pswControll,
                          keyboardType: TextInputType.phone,
                          obscureText: model.pswObscureText,
                          onChanged: (value) {
                            model.onChanged();
                          },
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(16),
                            color: Color(0xff000000),
                            fontWeight: FontWeight.w500,
                          ),
                          decoration: InputDecoration(
                              hintText: '输入密码',
                              border: InputBorder.none,
                              hintStyle: TextStyle(
                                fontSize: AdapterUtils.getSp(16),
                                color: Color(0xffcccccc),
                                fontWeight: FontWeight.w500,
                              )),
                        ),
                      ),
                      Offstage(
                        offstage: model.pswControll.text.toString().isEmpty
                            ? true
                            : false,
                        child: GestureDetector(
                          onTap: () {
                            model.clearPswText();
                          },
                          child: Container(
                            width: AdapterUtils.getWidth(45),
                            height: AdapterUtils.getHeight(45),
                            child: Icon(
                              Icons.cancel,
                              color: Color(0xffc2c2c2),
                              size: 17,
                            ),
                          ),
                        ),
                      ),
                      Offstage(
                        offstage: model.pswControll.text.toString().isEmpty
                            ? true
                            : false,
                        child: GestureDetector(
                          onTap: () {
                            model.onPswObscureText();
                          },
                          child: Container(
                              child: Image.asset('assets/images/eye.png')),
                        ),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(15),
                ),
                Container(
                  margin: EdgeInsets.symmetric(
                      horizontal: AdapterUtils.getWidth(50)),
                  alignment: Alignment.centerRight,
                  child: Text(
                    '忘记密码？',
                    style: TextStyle(
                      fontSize: AdapterUtils.getSp(12),
                      color: Color(0xff666666),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
                SizedBox(
                  height: AdapterUtils.getHeight(35),
                ),
                // Container(
                //   height: AdapterUtils.getHeight(50),
                //   width: AdapterUtils.screenWidth(),
                //    margin: EdgeInsets.symmetric(
                //       horizontal: AdapterUtils.getWidth(50)),
                //   child: FLLoadingButton(
                //     child: Text('登 录',style: TextStyle(
                //       color: Colors.white,
                //       fontSize: AdapterUtils.getSp(16),
                //       fontWeight: FontWeight.w500
                //     ),),
                //     color: Color(0xff15A1FF),
                //     disabledColor: Color(0xff15A1FF),
                //    disabledTextColor: Colors.grey.withAlpha(40),
                //     indicatorColor: Colors.white,
                //     textColor: Colors.white,
                //     loading: model.loading,

                //     minWidth: 200,
                //     indicatorOnly: true,
                //     onPressed: () {
                //       model.onLoad();
                //     }),
                // ),
                Container(
                    margin: EdgeInsets.symmetric(
                        horizontal: AdapterUtils.getWidth(50)),
                    width: AdapterUtils.screenWidth(),
                    height: AdapterUtils.getHeight(48),
                    child: FlatButton(
                        onPressed: model.isInput ? () {
                          model.onLogin(context);
                        } : null,
                        disabledColor: Color(0xff15A1FF).withAlpha(80),
                        color: Color(0xff15A1FF),
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.all(Radius.circular(4)),
                        ),
                        child: Text(
                          '登 录',
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(16),
                            color: Colors.white,
                            fontWeight: FontWeight.w500,
                          ),
                        ))),
                SizedBox(
                  height: AdapterUtils.getHeight(35),
                ),
                Container(
                  margin: EdgeInsets.symmetric(
                      horizontal: AdapterUtils.getWidth(50)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      InkWell(
                        child: Text(
                          '验证码登录',
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(14),
                            color: Color(0xff3D8EFF),
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          routePush(RegisterPage());
                        },
                        child: Text(
                          '我要注册',
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(14),
                            color: Color(0xff3D8EFF),
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      )
                    ],
                  ),
                )
              ],
            ),
          );
        },
      ),
    ));
  }
}
